<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <ui:composition template="layout.xhtml">
        <ui:define name="body">

            <h:form id="bairroForm" enctype="multipart/form-data">
                <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true" />

                <br/>
                <h3 class="title">Atualizar Bairro</h3>
                <p:growl id="messages" showDetail="true" autoUpdate="true"  /> 
                <p:panel id="personPanel" style="background: none; border: none;" 
                         styleClass="container_24 clearfix both ">
                    <h4 class="title">Dados Gerais</h4>

                    <p:outputLabel  value="Nome:" styleClass="grid_3"/>
                    <p:inputText id="nome" styleClass="grid_15"
                                 value="#{managerEditarBairro.bairro.nome}" required="true" requiredMessage="O campo nome é obrigatório" />
                    <div class="clear"/>

                    <p:outputLabel value="Cidade:" styleClass="grid_3"/>
                    <p:autoComplete styleClass="grid_16"  dropdown="true" converter="cidadeconverter"   
                                    var="cityValue" itemLabel="#{cityValue.nome.toString().concat(' - ')}#{cityValue.estado.sgl}" 
                                    itemValue="#{cityValue}" value="#{managerEditarBairro.cidade}"
                                    scrollHeight="200" forceSelection="true" required="true" requiredMessage="O campo cidade é obrigatório" 
                                    completeMethod="#{managerEditarBairro.autocompleteCity}" />  

                    <div class="clear"/>

                </p:panel>
                <h4 class="title">Georreferenciamento</h4>

                <p:panel id="geoPanel" style="background: none; border: none;" 
                         styleClass="container_24 clearfix ">

                    <p:gmap id="map" center="#{managerEditarBairro.centroMapa}" zoom="#{managerEditarBairro.zoomLevelMapa}" 
                            type="HYBRID" style="width:97%;height:500px" model="#{managerEditarBairro.mapModel}" > 

                        <p:ajax event="stateChange" listener="#{managerEditarBairro.onStateChange}"/>
                        <p:ajax event="pointSelect" listener="#{managerEditarBairro.handlePointClick}"
                                update="@this" onsuccess="getTipoMapa()" />
                        <p:ajax event="markerDrag" listener="#{managerEditarBairro.onMarkerDrag}" update="@this"/>

                    </p:gmap>

                    <div style="float: left; margin-top: -39px; margin-left: 75px;">
                        <p:commandButton value="Remover pontos" icon="ui-icon-trash" 
                                         update="@form" process="@this"
                                         actionListener="#{managerEditarBairro.removerMarkers()}"
                                         style="font-size: 12px; width: 140px !important"/>
                    </div>
                </p:panel>

                <br/>
                <div class="buttonAction">
                    <p:commandButton value="Salvar" icon="ui-icon-disk"
                                     update="@form"
                                     actionListener="#{managerEditarBairro.atualizar()}"
                                     styleClass="ui-priority-primary"/>

                    <p:button href="pesquisarbairro.xhtml" value="Cancelar" icon="ui-icon-trash" />
                </div>
            </h:form>

            <script language="JavaScript" type="text/javascript">
                function getTipoMapa(){
                    var mapa = $("div[title*='Show street map']").attr('style').contains('font-weight: 500;');
                    $("#bairroForm\\:tipoMapa").val(mapa);
                };
            </script>

        </ui:define> 
    </ui:composition>

</html>
